package org.example.sportdemo.controller;

import org.example.sportdemo.entity.GroundCollection;
import org.example.sportdemo.entity.GroundOrder;
import org.example.sportdemo.service.GroundCollectionService;
import org.example.sportdemo.service.GroundOrderService;
import org.example.sportdemo.utils.PageUtils;
import org.example.sportdemo.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/groundCollection")
public class GroundCollectionController {

    @Autowired
    private GroundCollectionService groundCollectionService;

    //分页
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params){

        PageUtils page = groundCollectionService.queryPage(params);

        R r = new R();
        r.put("page",page);
        return r;
    }

    //新增
    @RequestMapping(value = "/addGroundCollection")
    public R addCompetition(@RequestBody GroundCollection groundCollection){
        System.out.println(groundCollection);
        groundCollectionService.addGroundCollection(groundCollection);
        return R.ok().put("groundCollection",groundCollection);
    }

    //修改
    @RequestMapping(value = "/updateGroundCollection")
    public R updateGroundCollection(@RequestBody GroundCollection groundCollection){
        System.out.println(groundCollection);
        groundCollectionService.updateGroundCollection(groundCollection);
        return R.ok().put("groundCollection",groundCollection);
    }


    //根据id查询
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
        GroundCollection groundCollection = groundCollectionService.selectById(id);
        return R.ok().put("groundCollection",groundCollection);
    }

    //删除
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
        groundCollectionService.deleteByIds(ids);
        return R.ok();
    }

}
